package com.budwk.app.waterquality.controllers.admin;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.budwk.app.waterquality.models.WaterSectionInfoDetail;
import com.budwk.app.waterquality.services.WaterSectionInfoDetailService;
import com.budwk.starter.common.openapi.annotation.*;
import com.budwk.starter.common.page.PageUtil;
import com.budwk.starter.common.result.Result;
import com.budwk.starter.common.result.ResultCode;
import com.budwk.starter.log.annotation.SLog;
import lombok.extern.slf4j.Slf4j;
import org.nutz.dao.Cnd;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Strings;
import org.nutz.mvc.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@IocBean
@At("/waterquality/admin/water/section/info/detail")
@ApiDefinition(tag = "水质断面检测点成果基本信息详情表表")
@SLog(tag = "水质断面检测点成果基本信息详情表表")
@Slf4j
public class WaterSectionInfoDetailController {

    @Inject
    private WaterSectionInfoDetailService waterSectionInfoDetailService;

    @At
    @Ok("json")
    @POST
    @SLog(value = "分页查询水质断面检测点成果基本信息详情表表")
    @ApiOperation(name = "分页查询水质断面检测点成果基本信息详情表表")
    @ApiResponses(implementation = WaterSectionInfoDetail.class)
    @SaCheckPermission("waterquality.water.section.info.detail")
    public Result<?> list(@Param("..")WaterSectionInfoDetail bean,@Param("pageNo") int pageNo, @Param("pageSize") int pageSize, @Param("pageOrderName") String pageOrderName, @Param("pageOrderBy") String pageOrderBy) {
        Cnd cnd = Cnd.NEW();
        if (Strings.isNotBlank(pageOrderBy)) {
            cnd.orderBy(pageOrderName, PageUtil.getOrder(pageOrderBy));
        }

        return Result.data(waterSectionInfoDetailService.listPage(pageNo, pageSize, cnd));
    }

    @At
    @Ok("json")
    @POST
    @SLog(value = "新增水质断面检测点成果基本信息详情表表")
    @ApiOperation(name = "新增水质断面检测点成果基本信息详情表表")
    @ApiFormParams(
        implementation = WaterSectionInfoDetail.class
    )
    @ApiResponses
    public Result<?> create(@Param("..")WaterSectionInfoDetail w, HttpServletRequest req) {
        waterSectionInfoDetailService.create(w);
        return Result.success();
    }


    @At
    @Ok("json")
    @GET
    @ApiOperation(name = "删除水质断面检测点成果基本信息详情表表")
    public Result<?> getBySectionId(@Param("sectionId") String sectionId) {
        List<WaterSectionInfoDetail> list = waterSectionInfoDetailService.getBySectionId(sectionId);
        return Result.data(list);
    }
}
